﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Orf.Model;
using System.Windows.Forms;

namespace Orf.dto
{
    public class fapiaoZfDAO
    {
        SqlHelper sqlhelper = null;
        public fapiaoZfDAO()
        {
            sqlhelper = new SqlHelper();
        }

        /// <summary>
        /// 获取所有的当天的作废发票信息
        /// </summary>
        /// <returns></returns>
        public DataTable selectAllfpZfInfo()
        {
            DataTable dt = new DataTable();
            try
            {
                string strSql = "proc_selectAllfpzfInfo";
                dt = sqlhelper.ExecuteQuery(strSql, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
            	 MessageBox.Show(ex.Message.ToString());
            }
            return dt;
        }

        /// <summary>
        /// 取出结账日期、药房发药标志、医技项目执行标志，如果结账日期为空，
        /// 药房发药标志、医技项目执行标志为0，表示此发票可以作废，否则不能作废
        /// </summary>
        /// <param name="sfmxClass"></param>
        /// <param name="intType"></param>
        /// <returns></returns>
        public DataTable checkZdValue(MZ_SFMX sfmxClass,int intType)
        {
            DataTable dt = new DataTable();
            try
            {
                string strSql = "proc_fapiaoZfDAO";
                SqlParameter[] paras = new SqlParameter[]{
                     new SqlParameter("@fphm",sfmxClass.fPHM),
                     new SqlParameter("@czgh",sfmxClass.cZGH),
                     new SqlParameter("@intType",intType)};
                dt = sqlhelper.ExecuteQuery(strSql,paras,CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            return dt;
        }

        /// <summary>
        /// 更新收费明细表信息，如果是发票作废，置作废标志为1，如果是取消作废，置作废标志为0
        /// </summary>
        /// <param name="sfmxClass"></param>
        /// <param name="intType"></param>
        public void Update_Sfmx(MZ_SFMX sfmxClass,int intType)
        {
            int res = 0;
            try
            {
                string strSql = "proc_fapiaoZfDAO";
                SqlParameter[] paras = new SqlParameter[]{
                     new SqlParameter("@fphm",sfmxClass.fPHM),
                     new SqlParameter("@czgh",sfmxClass.cZGH),
                     new SqlParameter("@intType",intType)};
                res = sqlhelper.ExecuteNonQuery(strSql, paras, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            if (res >= 0)
            {
                return;
            }
            else
            {
                return;
            }
        }
        /// <summary>
        /// 更新处方01表的信息，发票作废的时候，把FPHM置为空，同时ORIFPHM存取发票号码，
        /// 作为取消作废时的，加到FPHM字段中。
        /// </summary>
        /// <param name="cf01Class"></param>
        /// <param name="intType"></param>
        public void Update_cf01(MZ_CF01 cf01Class, int intType)
        {
            int res = 0;
            try
            {
                string strSql = "proc_fapiaoZfDAO";
                SqlParameter[] paras = new SqlParameter[]{
                     new SqlParameter("@fphm",cf01Class.fPHM),
                     new SqlParameter("@czgh",""),
                     new SqlParameter("@intType",intType)};
                res = sqlhelper.ExecuteNonQuery(strSql, paras, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            if (res >= 0)
            {
                return;
            }
            else
            {
                return;
            }
        }

        /// <summary>
        /// 插入作废发票信息到表MZ_ZFFP中
        /// </summary>
        /// <param name="zffpClass"></param>
        /// <param name="intType"></param>
        /// <returns></returns>
        public int Inert_Zffp(MZ_ZFFP zffpClass,int intType)
        {
            int res = 0;
            try
            {
                string strSql = "proc_fapiaoZfDAO";
                SqlParameter[] paras = new SqlParameter[]{
                     new SqlParameter("@fphm",zffpClass.fPHM),
                     new SqlParameter("@czgh",zffpClass.zFGH),
                     new SqlParameter("@intType",intType)};
                res = sqlhelper.ExecuteNonQuery(strSql, paras, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            return res;
        }
    }
}
